package com.wc.alorithm_blue_bridge._数据结构.tire.Q3751;

import java.util.*;
import java.io.*;

/**
 * @Author congege
 * @Description 小蓝的神秘图书馆
 * https://www.lanqiao.cn/problems/3755/learning/?page=1&first_category_id=1
 * @Date Created in 2023/12/1-21:33
 */
public class Main {
    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args) {
        int n = nextInt();
        String[] ss = new String[n];
        for (int i = 0; i < n; i++) {
            ss[i] = nextLine();
        }
        Tire tree = new Tire(0);
        for (String s : ss) {
            tree.insert(s);
        }
        for (String s : ss) {
            out.println(tree.findLongestPrefix(s));
        }

        out.flush();
    }

    private static int nextInt() {
        int num = 0;
        try {
            num = Integer.parseInt(reader.readLine());
        } catch (Exception e) {
            return -1;
        }
        return num;
    }

    private static String nextLine() {
        String s = null;
        try {
            s = reader.readLine();
        } catch (Exception e) {
            return null;
        }
        return s;
    }
}

class Tire {
    private boolean isEnd;
    private final Map<Character, Tire> children;
    private final int floor;
    private int num;

    public Tire(int floor) {
        isEnd = false;
        children = new HashMap<>();
        this.floor = floor;
        this.num = 0;
    }

    public void insert(String word) {
        Tire node = this;
        int floor = this.floor;
        for (char c : word.toCharArray()) {
            ++floor;
            if (!node.children.containsKey(c)) {
                Tire child = new Tire(floor);
                node.children.put(c, child);
            }
            node = node.children.get(c);
            node.num++;
        }
        node.isEnd = true;
    }

    public boolean find(String word) {
        Tire node = this;
        for (char c : word.toCharArray()) {
            if (node.children.containsKey(c)) {
                node = node.children.get(c);
            } else {
                return false;
            }
        }
        return node.isEnd;
    }

    public int findLongestPrefix(String word) {
        int ans = 0;
        Tire node = this;
        for (char c : word.toCharArray()) {
            node = node.children.get(c);
            if (node.num > 1) {
                ans = node.floor;
            }
        }
        return ans;
    }
}



